﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.NamespaceDecl"/>.
    /// </summary>
    public class NamespaceDeclVM : BlockStatementVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(NamespaceDecl),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new NamespaceDeclVM((NamespaceDecl)codeObject, isDescription, dictionary); });
        }

        #endregion

        #region /* FIELDS */

        /// <summary>
        /// The expression should evaluate to a NamespaceRef (whether pre-existing or created by this statement).
        /// </summary>
        protected ExpressionVM _expressionVM;

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.NamespaceDecl"/>.
        /// </summary>
        public NamespaceDeclVM(NamespaceDecl namespaceDecl, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(namespaceDecl, isDescription, dictionary)
        {
            _expressionVM = (ExpressionVM)CreateVM(namespaceDecl.Expression, isDescription, dictionary);
        }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.NamespaceDecl"/> model.
        /// </summary>
        public NamespaceDecl NamespaceDecl
        {
            get { return (NamespaceDecl)CodeObject; }
        }

        /// <summary>
        /// The namespace <see cref="ExpressionVM"/>.
        /// </summary>
        public ExpressionVM ExpressionVM
        {
            get { return _expressionVM; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        public static readonly Brush StaticBorderBrush = Brushes.PaleTurquoise;
        public static readonly Brush StaticBackgroundBrush = Brushes.LightCyan;

        public override Brush BorderBrush
        {
            get { return StaticBorderBrush; }
        }

        public override Brush BackgroundBrush
        {
            get { return StaticBackgroundBrush; }
        }

        public override int BorderHPad
        {
            get { return 3; }
        }

        public override int BorderVPad
        {
            get { return 3; }
        }

        protected override void RenderArgument(CodeRenderer renderer, RenderFlags flags)
        {
            RenderFlags passFlags = (flags & RenderFlags.PassMask);
            _expressionVM.Render(renderer, passFlags);
        }

        public override void UnRender()
        {
            _expressionVM.UnRender();
            base.UnRender();
        }

        #endregion
    }
}
